<!-- UserModel.php-->
<?php 
	require '../common/ConnDB.php';
	require '../common/config.php';
	require 'Model.php';
	class CoModel extends Model{
		function __Construct(){
			parent::__Construct();
		}
		function getCoList(){
			$sql = 'select * from cooperate';
			$data = $this->conn->query($sql);
			//$this->conn = new ConnDB();
			return $data;
		}

		function getvideoinfor($videoname){
			$sql = "select * from videos where videoname like '%".$videoname."%' limit 0,10 ";;
			$data = $this->conn->query($sql);
			return $data;
		}

		function getUserByID($id){
			$sql = "select * from cooperate where coid=".$id;
			$data = $this->conn->query($sql);
			return $data;
		}

		function Updateco($data){
		  	$co = array(
				'coid' =>$_POST['coid'],
				'coproject' => $_POST['coproject'],
				'phone' => $_POST['phone'],
				'cointro' => $_POST['cointro'],
				);
			$sql="update cooperate set coid='$co[coid]',coproject='$co[coproject]',phone='$co[phone]',cointro='$co[cointro]' where coid=".$co['coid'];
			//echo "$sql";
			$result = $this->conn->query($sql);
			return $result;
		}

		function addco($data){
			//如果选择了照片，则上传照片文件
			if(!empty($_FILES["phone"]["name"])){
  				$phone = parent::uploadfile('phone','../images/',array('png','jpg','gif'));
  			}
		    else{
		  		$phone='';
		  	}
			$user = array(
				'coid' =>'',
				'coproject' => $data['coproject'],
				'phone' => $data['phone'],
				'cointro' => $data['cointro']
				);
			$keys = implode(',',array_keys($user));
			$values = implode("','",array_values($user));
			/*$sql = "insert into users values ('$user[uid]','$user[uname]','$user[password]','$user[gender]','$user[birthdate]','$user[hobby]','$user[degree]','$user[intro]','$user[pic]')";*/
			$sql="insert into cooperate ({$keys}) VALUES ('{$values}')";
			//echo "$sql";
			$result = $this->conn->query($sql);
			return $result;
		}

		function Delco($id){
			$sql = "Delete from cooperate where coid=".$id;
			$data = $this->conn->query($sql);
			return $data;
		}
	}
 ?>